Roman Calculator Repair
How do you know that a program works? Julius Caesar Enterprises has constructed a program they claim will convert Roman numerals to their decimal equivalents. See if it works, fix it if it fails, and submit a bill for consultant services.
Problem Statement
A programmer brings you the first program in the Python Code section and claims that it is a solution to the problem described in Roman Calculator Construction. The programmer also shows you the program's output for a number of test cases:
Roman numeral? I
1
Roman numeral? IX
9
Roman numeral? X
10
Roman numeral? XI
11
Roman numeral? XII
12
Roman numeral? XIV
14
Romannumeral? XL
40
Roman numeral? XLIX
49
Romannumeral? CMXCVII
997
Roman numeral? MCMXCIX
1999
Determine whether the program solves the problem. If it solves the problem, provide a complete set of test data. If it does not solve the problem point out the program's bugs to the programmer so she can fix them.
Analysis
11.1 Review the rules for Roman numbers given in Roman Calculator Construction. Show that the new program performs correctly for all the test cases in the problem statement.
Testing
11.2 Suppose another student in the class said, "Of course the program works: it gives the correct answers for lots of test cases. I am happy when my program works for one case." Explain why you agree or disagree.
Testing
11.3 Are the test cases in the problem statement sufficient to determine whether the program performs correctly? Why or why not.
Preparation
This case study introduces the use of recursion. No previous introduction to recursion is necessary.
Understanding the Program
How does one start to evaluate this program?
One way to try to get more information about the program is to run it, trying more test cases to see what answers they produce. Quite a few test cases have already been tried, and any new ones we would devise at this point would be mere "stabs in the dark." In order to get a better idea of how to test the program, we examine its code. Testing by itself can never completely show that a program works, so we must examine the code to convince ourselves of its correctness.
We focus on the program's flow of control. To understand the flow of control, we read the program from back to front, as we did in The Calendar Shop.
Stop & Help
What other aspects of the program might be interesting to examine besides its flow of control?
What does the main program do?
The main program looks like a typical "driver" program. It loops forever, apparently reading a Roman numeral, somehow converting it to a decimal, and printing it out. We guess that ReadlnRoman does both the reading and the conversion (since there is nothing else in the main program that can do this), and that it reads one Roman numeral per line (just like input). We check the output supplied by the programmer to verify our hunch.